﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Urb.Weather.Core.MeasureUnit;

namespace Urb.Weather.Core.Util
{
    public static class PressureHelper
    {
        public static decimal ConvertPressure(decimal fromPressure, PressureUnit fromUnit, PressureUnit toUnit)
        {
            if (fromUnit == toUnit)
                return fromPressure;

            switch (fromUnit)
            {
                case PressureUnit.InchHg:
                    switch (toUnit)
                    {
                        case PressureUnit.HPa:
                        case PressureUnit.Milibar:
                            return fromPressure * 33.86389M; // See: http://en.wikipedia.org/wiki/Inch_of_mercury
                        default:
                            throw new InvalidOperationException();
                    }
                case PressureUnit.HPa:
                case PressureUnit.Milibar:
                    switch (toUnit)
                    {
                        case PressureUnit.InchHg:
                            return fromPressure / 33.86389M; // See: http://en.wikipedia.org/wiki/Inch_of_mercury
                        case PressureUnit.Milibar:
                        case PressureUnit.HPa:
                            return fromPressure;
                        default:
                            throw new InvalidOperationException();
                    }
                default:
                    throw new InvalidOperationException();
            }
        }

        public static decimal ConvertPressureTo(this PressureUnit toUnit, decimal fromPressure, PressureUnit fromUnit)
        {
            return ConvertPressure(fromPressure, fromUnit, toUnit);
        }
    }
}
